package jdk14;

/**
 * JDK 14 新特性：Switch 增强
 */
public class SwitchDemo {
    /**
     * JDK 14 之前写法
     */
    public static String getWeek(Integer value) throws Exception {
        switch (value) {
            case 0:
                return "星期日";
            case 1:
                return "星期一";
            case 2:
                return "星期二";
            case 3:
                return "星期三";
            case 4:
                return "星期四";
            case 5:
                return "星期五";
            case 6:
                return "星期六";
            default:
                throw new Exception("数据错误");
        }
    }

    /**
     * JDK 14 写法
     */
    public static String getWeekByJDK14(Integer value) throws Exception {
        return switch (value) {
            case 0 -> "星期日";
            case 1 -> "星期一";
            case 2 -> "星期二";
            case 3 -> "星期三";
            case 4 -> "星期四";
            case 5 -> "星期五";
            case 6 -> "星期六";
            default -> throw new Exception("数据错误");

        };
    }

    public static void main(String[] args) throws Exception {
        System.out.println(getWeek(1));
        System.out.println(getWeekByJDK14(5));
    }
}